﻿using System.Collections.Generic;

namespace DM4Script
{
    public partial class ScriptParse
    {
        /// expression ::= primary binoprhs
        private Prototypes.ExprAst ParseExpression(Queue<string> taskExists)
        {
            Prototypes.ExprAst lhs = ParsePrimary(taskExists);
            if (lhs == null) return null;

            return ParseBinOpRHS(0, lhs, taskExists);
        }

        /// numberexpr ::= number
        private Prototypes.ExprAst ParseNumberExpr()
        {
            Prototypes.ExprAst result = new Prototypes.NumberExprAst(_numVal);
            GetNextToken(); // получаем число
            return result;
        }

        /// parenexpr ::= '(' expression ')'
        private Prototypes.ExprAst ParseParenExpr(Queue<string> taskExists)
        {
            GetNextToken(); // получаем (.
            Prototypes.ExprAst v = ParseExpression(taskExists);
            if (v == null) return null;

            if (_curTok != ')')
                return Error("expected ')'");
            GetNextToken(); // получаем ).
            return v;
        }
    }
}
